using System;
using System.ComponentModel;
using System.Drawing;
using System.IO.Ports;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Advance;

public class FormUPS : Form
{
	private IContainer components = null;

	private GroupBox groupBox3;

	private ComboBox comboBox_port;

	private Label label11;

	private ComboBox comboBox_stop;

	private Label label14;

	private Label label12;

	private ComboBox comboBox_data;

	private ComboBox comboBox_baudrate;

	private ComboBox comboBox_parity;

	private Label label13;

	private Label label15;

	private Button button1;

	public FormUPS()
	{
		InitializeComponent();
	}

	private void button1_Click(object sender, EventArgs e)
	{
		CommInfo comminfo = new CommInfo();
		comminfo.Baudrate = Convert.ToInt32(comboBox_baudrate.Text);
		comminfo.Databits = Convert.ToInt32(comboBox_data.Text);
		comminfo.Parity = comboBox_parity.Text;
		comminfo.Portname = comboBox_port.Text;
		comminfo.Stopbits = comboBox_stop.Text;
		UPSManager.Instance.Serialize(comminfo);
		if (UPSManager.Instance.IsOpen)
		{
			UPSManager.Instance.Close();
		}
		UPSManager.Instance.Cominfo = comminfo;
		UPSManager.Instance.Init();
	}

	private void FormUPS_Load(object sender, EventArgs e)
	{
		ComboBox.ObjectCollection items = comboBox_port.Items;
		object[] portNames = SerialPort.GetPortNames();
		items.AddRange(portNames);
		CommInfo comminfo = UPSManager.Instance.Deserialize();
		if (comminfo != null)
		{
			comboBox_baudrate.Text = comminfo.Baudrate.ToString();
			comboBox_data.Text = comminfo.Databits.ToString();
			comboBox_parity.Text = comminfo.Parity.ToString();
			comboBox_port.Text = comminfo.Portname;
			comboBox_stop.Text = comminfo.Stopbits;
		}
		ApplyResources();
	}

	private void ApplyResources()
	{
		groupBox3.Text = Lang.Txt("ADD.UPS.UPSSet");
		label11.Text = Lang.Txt("ADD.UPS.COM");
		label12.Text = Lang.Txt("ADD.UPS.BaudRate");
		label13.Text = Lang.Txt("ADD.UPS.ParityCheck");
		label15.Text = Lang.Txt("ADD.UPS.DataBits");
		label14.Text = Lang.Txt("ADD.UPS.StopBits");
		button1.Text = Lang.Txt("ADD.UPS.Set");
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.groupBox3 = new System.Windows.Forms.GroupBox();
		this.comboBox_port = new System.Windows.Forms.ComboBox();
		this.label11 = new System.Windows.Forms.Label();
		this.comboBox_stop = new System.Windows.Forms.ComboBox();
		this.label14 = new System.Windows.Forms.Label();
		this.label12 = new System.Windows.Forms.Label();
		this.comboBox_data = new System.Windows.Forms.ComboBox();
		this.comboBox_baudrate = new System.Windows.Forms.ComboBox();
		this.comboBox_parity = new System.Windows.Forms.ComboBox();
		this.label13 = new System.Windows.Forms.Label();
		this.label15 = new System.Windows.Forms.Label();
		this.button1 = new System.Windows.Forms.Button();
		this.groupBox3.SuspendLayout();
		base.SuspendLayout();
		this.groupBox3.Controls.Add(this.comboBox_port);
		this.groupBox3.Controls.Add(this.label11);
		this.groupBox3.Controls.Add(this.comboBox_stop);
		this.groupBox3.Controls.Add(this.label14);
		this.groupBox3.Controls.Add(this.label12);
		this.groupBox3.Controls.Add(this.comboBox_data);
		this.groupBox3.Controls.Add(this.comboBox_baudrate);
		this.groupBox3.Controls.Add(this.comboBox_parity);
		this.groupBox3.Controls.Add(this.label13);
		this.groupBox3.Controls.Add(this.label15);
		this.groupBox3.Font = new System.Drawing.Font("宋体", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
		this.groupBox3.Location = new System.Drawing.Point(13, 13);
		this.groupBox3.Margin = new System.Windows.Forms.Padding(4);
		this.groupBox3.Name = "groupBox3";
		this.groupBox3.Padding = new System.Windows.Forms.Padding(4);
		this.groupBox3.Size = new System.Drawing.Size(289, 186);
		this.groupBox3.TabIndex = 63;
		this.groupBox3.TabStop = false;
		this.groupBox3.Text = "串口设置";
		this.comboBox_port.FormattingEnabled = true;
		this.comboBox_port.Location = new System.Drawing.Point(164, 21);
		this.comboBox_port.Margin = new System.Windows.Forms.Padding(4);
		this.comboBox_port.Name = "comboBox_port";
		this.comboBox_port.Size = new System.Drawing.Size(103, 23);
		this.comboBox_port.TabIndex = 59;
		this.label11.ForeColor = System.Drawing.SystemColors.ControlText;
		this.label11.ImeMode = System.Windows.Forms.ImeMode.NoControl;
		this.label11.Location = new System.Drawing.Point(8, 21);
		this.label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label11.Name = "label11";
		this.label11.Size = new System.Drawing.Size(133, 24);
		this.label11.TabIndex = 58;
		this.label11.Text = "COM:";
		this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
		this.comboBox_stop.FormattingEnabled = true;
		this.comboBox_stop.Items.AddRange(new object[3] { "None", "One", "Two" });
		this.comboBox_stop.Location = new System.Drawing.Point(163, 155);
		this.comboBox_stop.Margin = new System.Windows.Forms.Padding(4);
		this.comboBox_stop.Name = "comboBox_stop";
		this.comboBox_stop.Size = new System.Drawing.Size(104, 23);
		this.comboBox_stop.TabIndex = 57;
		this.comboBox_stop.Text = "One";
		this.label14.ForeColor = System.Drawing.SystemColors.ControlText;
		this.label14.ImeMode = System.Windows.Forms.ImeMode.NoControl;
		this.label14.Location = new System.Drawing.Point(8, 154);
		this.label14.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label14.Name = "label14";
		this.label14.Size = new System.Drawing.Size(133, 24);
		this.label14.TabIndex = 53;
		this.label14.Text = "停止位:";
		this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
		this.label12.ForeColor = System.Drawing.SystemColors.ControlText;
		this.label12.ImeMode = System.Windows.Forms.ImeMode.NoControl;
		this.label12.Location = new System.Drawing.Point(8, 54);
		this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label12.Name = "label12";
		this.label12.Size = new System.Drawing.Size(133, 24);
		this.label12.TabIndex = 50;
		this.label12.Text = "波特率:";
		this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
		this.comboBox_data.FormattingEnabled = true;
		this.comboBox_data.Items.AddRange(new object[2] { "0", "8" });
		this.comboBox_data.Location = new System.Drawing.Point(164, 121);
		this.comboBox_data.Margin = new System.Windows.Forms.Padding(4);
		this.comboBox_data.Name = "comboBox_data";
		this.comboBox_data.Size = new System.Drawing.Size(103, 23);
		this.comboBox_data.TabIndex = 56;
		this.comboBox_data.Text = "8";
		this.comboBox_baudrate.FormattingEnabled = true;
		this.comboBox_baudrate.Items.AddRange(new object[2] { "1200", "9600" });
		this.comboBox_baudrate.Location = new System.Drawing.Point(164, 54);
		this.comboBox_baudrate.Margin = new System.Windows.Forms.Padding(4);
		this.comboBox_baudrate.Name = "comboBox_baudrate";
		this.comboBox_baudrate.Size = new System.Drawing.Size(103, 23);
		this.comboBox_baudrate.TabIndex = 54;
		this.comboBox_baudrate.Text = "9600";
		this.comboBox_parity.FormattingEnabled = true;
		this.comboBox_parity.Items.AddRange(new object[3] { "Odd", "Even", "None" });
		this.comboBox_parity.Location = new System.Drawing.Point(164, 90);
		this.comboBox_parity.Margin = new System.Windows.Forms.Padding(4);
		this.comboBox_parity.Name = "comboBox_parity";
		this.comboBox_parity.Size = new System.Drawing.Size(103, 23);
		this.comboBox_parity.TabIndex = 55;
		this.comboBox_parity.Text = "None";
		this.label13.ForeColor = System.Drawing.SystemColors.ControlText;
		this.label13.ImeMode = System.Windows.Forms.ImeMode.NoControl;
		this.label13.Location = new System.Drawing.Point(8, 88);
		this.label13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label13.Name = "label13";
		this.label13.Size = new System.Drawing.Size(133, 24);
		this.label13.TabIndex = 51;
		this.label13.Text = "奇偶校验:";
		this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
		this.label15.ForeColor = System.Drawing.SystemColors.ControlText;
		this.label15.ImeMode = System.Windows.Forms.ImeMode.NoControl;
		this.label15.Location = new System.Drawing.Point(8, 119);
		this.label15.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label15.Name = "label15";
		this.label15.Size = new System.Drawing.Size(133, 24);
		this.label15.TabIndex = 52;
		this.label15.Text = "数据位:";
		this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
		this.button1.Location = new System.Drawing.Point(354, 84);
		this.button1.Name = "button1";
		this.button1.Size = new System.Drawing.Size(97, 42);
		this.button1.TabIndex = 64;
		this.button1.Text = "设置";
		this.button1.UseVisualStyleBackColor = true;
		this.button1.Click += new System.EventHandler(button1_Click);
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 15f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(800, 450);
		base.Controls.Add(this.button1);
		base.Controls.Add(this.groupBox3);
		base.Name = "FormUPS";
		this.Text = "UPS串口设置";
		base.Load += new System.EventHandler(FormUPS_Load);
		this.groupBox3.ResumeLayout(false);
		base.ResumeLayout(false);
	}
}
